<?php

/**
 * Description of request
 *
 * @author adrian
 */
class Router {
    /**
     *
     * @var array
     */
    public static $params = array();

    /**
     *
     * @var string
     */
    private static $_defController = 'template';

    /**
     *
     * @var string
     */
    private static $_defAction = 'index';

    /**
     *
     * @var string
     */
    public static $controller = '';

    /**
     *
     * @var string
     */
    public static $action = '';

    /**
     *
     */
    public static function find_uri() {
        $scriptPath = Router::parseArray("/framework/index.php");
        $adress = parse_url($_SERVER['REQUEST_URI']);        
        $path = Router::parseArray($adress['path']);
        foreach($scriptPath as $el){
            array_shift($path);
        }
        if(!empty($path)) {            
            Router::$controller = $path[0];
            array_shift($path);
        }            
        else{
            Router::$controller = Router::$_defController;
        }
        if(!empty($path)){
            Router::$action = $path[0];
            array_shift($path);    
        }            
        else{
            Router::$action = Router::$_defAction;
        }
        Router::$params = $path;
    }   
    
    private static function parseArray($string){
        return explode("/",trim($string,"/"));
    }
    
}

?>
